# Maintainer: J. Peter Mugaas <jpmugaas@suddenlink.net>

_pyname=oslo.utils
_realname=oslo-utils
pkgbase=mingw-w64-python-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-python-${_realname}")
provides=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
conflicts=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
replaces=("${MINGW_PACKAGE_PREFIX}-python3-${_realname}")
pkgver=6.1.0
pkgrel=2
pkgdesc="Oslo Utility library (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url='https://github.com/openstack/oslo.utils'
license=('spdx:Apache-2.0')
depends=("${MINGW_PACKAGE_PREFIX}-python-debtcollector"
         "${MINGW_PACKAGE_PREFIX}-python-iso8601"
         "${MINGW_PACKAGE_PREFIX}-python-netaddr"
         "${MINGW_PACKAGE_PREFIX}-python-netifaces"
         "${MINGW_PACKAGE_PREFIX}-python-oslo-i18n"
         "${MINGW_PACKAGE_PREFIX}-python-packaging"
         "${MINGW_PACKAGE_PREFIX}-python-pbr"
         "${MINGW_PACKAGE_PREFIX}-python-pyparsing"
         "${MINGW_PACKAGE_PREFIX}-python-pytz")
makedepends=("${MINGW_PACKAGE_PREFIX}-python-setuptools")
checkdepends=("${MINGW_PACKAGE_PREFIX}-python-oslotest"
              "${MINGW_PACKAGE_PREFIX}-python-ddt"
              "${MINGW_PACKAGE_PREFIX}-python-eventlet")
source=("https://pypi.org/packages/source/${_realname::1}/${_pyname}/${_pyname}-${pkgver}.tar.gz")
sha256sums=('76bc0108d50aca972b68fec8298e791b5fbcbeb9a51a27c6986b41b0a6a62eeb')

prepare() {
  cd "${srcdir}/${_pyname}-${pkgver}"

  # Use python 3's standard monotonic function
  sed -i '/monotonic/d' requirements.txt
  sed -i 's/from monotonic import monotonic/from time import monotonic/' oslo_utils/timeutils.py

  # Set version for setuptools_scm
  export SETUPTOOLS_SCM_PRETEND_VERSION=$pkgver
  export PBR_VERSION=$pkgver
}

build() {
  cd "${srcdir}/${_pyname}-${pkgver}"
  ${MINGW_PREFIX}/bin/python setup.py build
}

check() {
  cd "${srcdir}/${_pyname}-${pkgver}"
  ${MINGW_PREFIX}/bin/stestr run
}

package() {
  cd "${srcdir}/${_pyname}-${pkgver}"

  MSYS2_ARG_CONV_EXCL="--prefix=;--install-scripts=;--install-platlib=" \
  ${MINGW_PREFIX}/bin/python setup.py install --prefix=${MINGW_PREFIX} \
    --root="${pkgdir}" --optimize=1 --skip-build

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/python-${_realname}/LICENSE"
}
